<template>
  <div>
    <h1>温州理工滨海校区</h1>
    <input type="text" v-model="studentId">
    <button @click="searchStudent">搜索</button>

    <div v-if="student">
      <h2>学生信息：</h2>
      <p>学号: {{ student.id }}</p>
      <p>姓名: {{ student.name }}</p>
      <p>年龄: {{ student.age }}</p>
      <p>专业: {{ student.learn }}</p>
    </div>
  </div>
</template>

<script>
export default {
  name: 'CampusBinhai',
  data() {
    return {
      studentId: '',
      student: null
    }
  },
  methods: {
    searchStudent() {
      if (this.studentId.trim() !== '') {
        this.student = this.fetchStudentInfo(this.studentId);
      } else {
        this.student = null;
      }
    },
    fetchStudentInfo(studentId) {
      return {
        name: '王涛',
        id: studentId,
        age: '20',
        learn: '计算机科学与技术'
      };
    }
  }
}
</script>